*************************
/* GETTING THE DATASET */
*************************
clear all
set more off

global folder /Users/yasenov/Dropbox/mariel_boatlift/revision_version/revision_data/
use $folder/raw_march_cps.dta

keep if year >= 1972 & year <= 1991
drop if metarea == 9997 | metarea == 9998 | metarea == 9999
keep if wtsupp > 0
keep if age >= 16 & age <= 65

***************************
/* DEMOGRAPHIC VARIABLES */
***************************
gen low_skilled = educ < 72  
gen college = educ >= 110
gen male = sex == 1
gen white = (race == 100 & hispan == 0)
gen black = (race == 200 & hispan == 0)
gen hisp = hispan > 0
gen cuban = hispan == 300
gen young = age < 30
gen manuf = .
replace manuf = 1 if ind1950 > 300 & ind1950 < 500
replace manuf = 0 if manuf == . & ind1950 != 0
gen bluecol = .
replace bluecol = 1 if ind1950 !=0 & ind1950 < 500
replace bluecol = 0 if bluecol == . & ind1950 != 0
gen whitecol = .
replace whitecol = 1 if ind1950 > 700
replace whitecol = 0 if whitecol == . & ind1950 != 0
gen hisp_lowskilled = (hispan > 0 & educ < 72)
gen cuban_lowskilled = cuban == 1 & low_skilled == 1

****************************
/* LABOR MARKET VARIABLES */
****************************
* fix topcodes
replace incwage=50000*1.5 if year>=1968 & year<=1981 & incwage==50000
replace incwage=75000*1.5 if year>=1982 & year<=1984 & incwage==75000
replace incwage=99999*1.5 if year>=1985 & year<=1987 & incwage==99999
replace incwage=199998*1.5 if year>=1988 & year<=1995 & incwage==199998
replace incwage = . if incwage<0

* extrapolating the weeksworked bins
replace wkswork2 = 0 if wkswork2 == 0
replace wkswork2 = 7 if wkswork2 == 1
replace wkswork2 = 20 if wkswork2 == 2
replace wkswork2 = 33 if wkswork2 == 3
replace wkswork2 = 44 if wkswork2 == 4
replace wkswork2 = 48.5 if wkswork2 == 5
replace wkswork2 = 51 if wkswork2 == 6
replace wkswork1 = wkswork2 if wkswork1 == . & wkswork2 != .
drop wkswork2

* extrapolating the weeksunemployed bins
replace wksunem2 = 2.5 if wksunem2 == 1
replace wksunem2 = 7.5 if wksunem2 == 2
replace wksunem2 = 12.5 if wksunem2 == 3
replace wksunem2 = 20.5 if wksunem2 == 4
replace wksunem2 = 33 if wksunem2 == 5
replace wksunem2 = 46 if wksunem2 == 6
replace wksunem2 = . if wksunem2 == 9
replace wksunem1 = wksunem2 if (wksunem1 == . & wksunem2 != .) | (wksunem1 == 99 & wksunem2 !=.)
replace wksunem1 = . if wksunem1 == 99
drop wksunem2

rename wksunem1 weeksunemp
gen wage = incwage / wkswork1
rename incwage wage_yearly
drop wkswork1

replace weeksunemp = weeksunemp / 52

global vars wage wage_yearly
foreach i of global vars {
	replace `i' = `i' * 1.970508037 if year == 1972 
	replace `i' = `i' * 1.854428813 if year == 1973 
	replace `i' = `i' * 1.67047874 if year == 1974 
	replace `i' = `i' * 1.530571296 if year == 1975 
	replace `i' = `i' * 1.447016669 if year == 1976 
	replace `i' = `i' * 1.359074187 if year == 1977 
	replace `i' = `i' * 1.26272953 if year == 1978 
	replace `i' = `i' * 1.135017842 if year == 1979 
	replace `i' = `i' * 1 			if year == 1980 	
	replace `i' = `i' * 0.905974729 if year == 1981 
	replace `i' = `i' * 0.853418002 if year == 1982 
	replace `i' = `i' * 0.827279757 if year == 1983 
	replace `i' = `i' * 0.792654883 if year == 1984 
	replace `i' = `i' * 0.765641264 if year == 1985 
	replace `i' = `i' * 0.751039274 if year == 1986 
	replace `i' = `i' * 0.725093956 if year == 1987 
	replace `i' = `i' * 0.69653773 if year == 1988
	replace `i' = `i' * 0.664689936 if year == 1989
	replace `i' = `i' * 0.630523963 if year == 1990 
	replace `i' = `i' * 0.605014431 if year == 1991
	gen log`i' = log(`i')
	}

label define metarea_lbl 4481 "Anaheim-Santa Ana, CA", modify
label define metarea_lbl 8280 "Tampa-St. Petersburg, FL", modify
label define metarea_lbl 5720 "Norfolk-Virginia Beach, VA", modify
label define metarea_lbl 5120 "Minneapolis-St Paul, MN", modify

sort metarea year
saveold $folder/aux_march.dta, replace

*********
*********

global vars college low_skilled male white black hisp cuban young age manuf whitecol bluecol hisp_lowskilled cuban_lowskilled
collapse (mean) $vars [pw=wtsupp], by(year metarea)
saveold $folder/msa_controls_march.dta, replace
